<template>
  <view class="container">
    <!-- 顶部组件 -->
    <u-navbar
      id="nav-bar"
      :is-back="true"
      :background="{ background: '#fff' }"
      border-bottom
      title="共享收益明细"
    ></u-navbar>

    <view class="tabs-box">
      <u-tabs
        :list="tabList"
        :is-scroll="false"
        :current="current"
        @change="onChange"
      ></u-tabs>
    </view>

    <view class="content">
      <view class="searchBox">
        <view class="date">
          <template v-if="!startTime">近三个月明细</template>
          <template v-else>{{ startTime }}～{{ endTime }}</template>
        </view>
        <view class="do" @click="handleChooseTime">
          <image
            class="do-img"
            src="https://file.hjsfpay.com/image/20230613/profit-date.png"
            mode="widthFix"
          ></image>
          <text>选择日期</text>
        </view>
      </view>

      <mescroll-body
        ref="mescrollRef"
        @init="mescrollInit"
        top="0"
        @down="downCallback"
        :up="upOption"
        @up="upCallback"
      >
        <view class="list">
          <template v-if="current === 0">
            <view v-for="(item, index) in list" :key="index" class="rzItem">
              <image
                class="logo"
                mode="widthFix"
                src="https://file.hjsfpay.com/image/20230613/icon-rzmx.png"
              />
              <view class="info">
                <view class="time">{{item.createDate}}</view>
                <view class="num">+{{ item.amount }}</view>
              </view>
            </view>
          </template>
          <template v-else>
            <view v-for="(item, index) in list" :key="index" class="item">
              <view class="row">
                <view class="left">
                  <image
                    class="logo"
                    mode="widthFix"
                    src="https://file.hjsfpay.com/image/20230613/star-company.png"
                  />
                  <text class="name">
                    {{ item.cardNo }}
                  </text>
                </view>
                <view
                  v-if="item.status === 0"
                  class="right"
                  style="color: #3275fa"
                  >等待兑换</view
                >
                <view
                  v-if="item.status === 1"
                  class="right"
                  style="color: #3275fa"
                  >兑换中</view
                >
                <view
                  v-if="item.status === 2"
                  class="right"
                  style="color: #3275fa"
                  >兑换成功</view
                >
                <view v-else class="right" style="color: #f53131">兑换失败</view>
              </view>
              <view class="row margin-top-30">
                <view class="left">
                  <text class="time">
                    {{ item.createTime }}
                  </text>
                </view>
                <view class="right"
                  ><text class="num">{{ item.amount }}</text></view
                >
              </view>
              <view
                v-if="item.statusMsg && item.statusMsg != '成功'"
                class="row margin-top-30"
              >
                <view class="tip">{{ item.statusMsg }}</view>
              </view>
            </view>
          </template>
        </view>
      </mescroll-body>
    </view>
    <u-calendar
      v-model="showCalendar"
      mode="range"
      @change="dateConfirm"
    ></u-calendar>
  </view>
</template>
<script>
import service from '@/common/service.js';
import util from '@/common/util.js';
import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins.js';

export default {
  mixins: [MescrollMixin],
  data() {
    return {
      list: [],
      upOption: {
        page: {
          num: 0,
          size: 10,
        },
        noMoreSize: 5,
        empty: {
          tip: '',
        },
      },
      mescroll: null,
      startTime: '',
      endTime: '',
      showCalendar: false,
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
      },
      type: 0,
      tabList: [
        {
          name: '入账明细',
          count: 0,
        },
        {
          name: '提现明细',
          count: 0,
        },
      ],
      current: 0,
    };
  },
  onLoad(options) {},
  methods: {
    mescrollInit: function (mescroll) {
      this.mescroll = mescroll;
    },
    downCallback() {
      this.list = [];
      this.mescroll.resetUpScroll();
    },
    upCallback(page) {
      this.getData(page);
    },
    getData(page) {
      const that = this;
      if (this.current === 0) {
        const params = {
          pageNumber: page.num,
          pageSize: page.size,
          beginDate: that.startTime,
          endDate: that.endTime,
          type: '',
        };
        service.getMyFlow(
          params,
          function (res) {
            if (res.data && res.status === 1) {
              that.mescroll.endSuccess(res.data.data.length);
              if (page.num == 1) that.list = [];
              that.list = that.list.concat(res.data.data);
            }
          },
          function () {}
        );
      } else {
        const params = {
          pageNumber: page.num,
          pageSize: page.size,
          beginDate: this.startTime,
          endDate: this.endTime,
          type: '5',
        };
        service.getWithdrawPage(
          params,
          function (res) {
            if (res.data && res.status === 1) {
              that.mescroll.endSuccess(res.data.data.length);
              if (page.num == 1) that.list = [];
              that.list = that.list.concat(res.data.data);
            }
          },
          function (res) {}
        );
      }
    },
    handleTransferDetail() {
      uni.navigateTo({
        url: '/pages/dataCenter/donationDetail',
      });
    },
    handleChooseTime() {
      this.showCalendar = true;
    },
    dateConfirm(e) {
      const { startDate, endDate } = e;
      this.startTime = startDate;
      this.endTime = endDate;
      this.list = [];
      this.mescroll.resetUpScroll();
    },
    change(res) {},
    navigateTo(url) {
      uni.navigateTo({
        url: url,
      });
    },
    onChange(index) {
      this.current = index;
      this.list = [];
      this.mescroll.resetUpScroll();
    },
  },
};
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  min-height: 100%;
  padding: 0;
  background: #ffffff;
  box-sizing: border-box;
}

.content {
  width: 100%;
  padding: 0;
  background-color: #f5f5f5;
}

.searchBox {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 90rpx;
  padding: 0 20rpx;
  box-sizing: border-box;
  .date {
    line-height: 1;
    font-size: 24rpx;
  }

  .do {
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    align-items: center;
    line-height: 1;
    font-size: 24rpx;
    width: 120rpx;
    height: 70rpx;
    .do-img {
      margin-right: 10rpx;
      width: 24rpx;
      height: auto;
    }
  }
}

.list {
  width: 100%;
  padding: 10rpx 20rpx;
  box-sizing: border-box;
}

.item {
  position: relative;
  margin-bottom: 30rpx;
  width: 100%;
  height: auto;
  padding: 30rpx;
  background: #ffffff;
  border-radius: 10rpx;
  overflow: hidden;
}

.row {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0;
  box-sizing: border-box;
  .left {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    .logo {
      width: 28rpx;
      height: 28rpx;
    }

    .name {
      margin-left: 10rpx;
      font-size: 28rpx;
      line-height: 28rpx;
      color: #222222;
      font-weight: bold;
      text-align: left;
    }
    .time {
      font-size: 24rpx;
      font-weight: 400;
      color: #999999;
      line-height: 1;
    }
  }
  .right {
    font-size: 24rpx;
    font-weight: 400;
    line-height: 1;
    .num {
      font-size: 28rpx;
      font-family: DIN;
      font-weight: bold;
      color: #cc921f;
      line-height: 1;
    }
  }
  .tip {
    font-size: 24rpx;
    font-weight: 400;
    color: #f53131;
    line-height: 1.5;
  }
}

.rzItem {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
  width: 100%;
  height: auto;
  padding: 30rpx;
  background: #ffffff;
  border-radius: 10rpx;
  overflow: hidden;
  .logo {
    width: 72rpx;
    height: auto;
  }
  .info {
    padding-left: 20rpx;
    width: calc(100% - 72rpx);
    .time {
      width: 100%;
      font-size: 28rpx;
      font-family: PingFang SC, sans-serif;
      font-weight: normal;
      color: #222222;
      text-align: left;
    }
    .num {
      margin-top: 22rpx;
      width: 100%;
      font-size: 28rpx;
      font-family: DIN, sans-serif;
      font-weight: bold;
      color: #f53131;
      text-align: left;
    }
  }
}

.margin-top-30 {
  margin-top: 30rpx;
}
</style>
